<?php
namespace Admin\Controller;
use Think\Controller;
class AnswerController extends CommonController {
    public function index(){
    	
        $this->show();
    }

    public  function comment_list(){
    	$sql='select t1.*,t2.title ,t2.status a_status ,t2.status ,t3.nickname from answer t1 inner join question t2 on t1.qid = t2.id inner join user t3 on t1.uid = t3.id order by t1.id';
        $answers=M()->query($sql);

    	$this->assign('answers',$answers);

        $this->show();
    }

    // 评论删除
    public function comment_del(){
           $id=I('post.id');
        if (M('answer')->where(array('id'=>$id))->find()) {
        	M('answer')->where(array('id'=>$id))->delete();
        	$arr=array(
        		'error'=>1,
        		'info'=>'删除成功'
        		);
        	echo json_encode($arr);
        	exit;
        }else{
        	$arr=array(
        		'error'=>2,
        		'info'=>'删除失败'
        		);
        	echo json_encode($arr);
        	exit;
        }
    }

    // 批量删除
    public function  delAll(){
         $str=I('post.str');
       $str=rtrim($str,",");
       $sql="delete from answer where id in (".$str.")";
       // var_dump($sql);
       if (M()->execute($sql)) {
         $arr=array(
          'error'=>1,
          'info'=>'批量删除成功'
          );
         echo json_encode($arr);
         exit;
       }else{
            $arr=array(
          'error'=>2,
          'info'=>'批量删除失败'
          );
         echo json_encode($arr);
         exit;
       }
    }

}//类的结尾